In [2]:
import os
import ogr
In [3]:
driver_name = 'ESRI Shapefile'
# driver_name = 'FileGDB'
driver = ogr.GetDriverByName(driver_name)
print driver
In [4]:
this_file_directory = os.path.dirname(os.path.realpath('__file__'))
shapefile_path = os.path.join(this_file_directory, 'CA_counties', 'CA_counties.shp')
print os.path.isfile(shapefile_path)
In [5]:
ds = driver.Open(shapefile_path)
In [6]:
# dir(ds)
In [7]:
layer = ds.GetLayer(0)
print layer
In [9]:
print dir(layer)
In [10]:
layer.GetFeatureCount()
Out[10]:
In [49]:
feature = layer.GetFeature(0)
print feature.GetGeometryRef().Simplify(.1).ExportToJson()
dir(feature.GetGeometryRef())
Out[49]:
The unit for Simplify is tolerance, i.e. the maximal distance a vertex can be pleased from its original location.
In [34]:
for feature in layer:
print feature.name
# feature.ExportToGeoJson()
In [ ]: